module.exports = app => {
  const { STRING, INTEGER, BOOLEAN, JSON, TEXT } = app.Sequelize
  const { mediaUrl } = app.config

  const Shop = app.model.define(
    'shops',
    {
      // id: {
      //   type: INTEGER,
      //   primaryKey: true
      // },
      brand: {
        type: STRING(32),
        allowNull: false
      },
      model: {
        type: STRING(60)
      },
      manufacturerYear: {
        type: STRING(60)
      },
      mileage: {
        type: STRING(60)
      },
      bodyType: {
        type: STRING(60)
      },
      seatsNo: {
        type: INTEGER
      },
      doorsNo: {
        type: INTEGER
      },
      vehicleTransmissionType: {
        type: STRING(60)
      },
      driveType: {
        type: STRING(60)
      },
      cylindersNo: {
        type: INTEGER
      },
      fuelType: {
        type: STRING(60)
      },
      vimNumber: {
        type: STRING(60)
      },
      engineCapacity: {
        type: STRING(60)
      },
      gearsNo: {
        type: INTEGER
      },
      price: {
        type: INTEGER
      },
      truePrice: {
        type: INTEGER
      },
      title: STRING(255),
      cover: STRING(255),
      content: TEXT,

      phoneNo: STRING(255),
      name: STRING(255),
      email: STRING(255),

      medias: {
        type: JSON
      },
      active: BOOLEAN
    },
    {
      getterMethods: {
        mediasUrl() {
          const mediasUrl = []

          this.medias.forEach(item => {
            mediasUrl.push(`${mediaUrl}/${item}`)
          })

          return mediasUrl
        },
        coverUrl() {
          return `${mediaUrl}/${this.cover}`
        }
      }
    }
  )

  // Shop.associate = function() {
  //   app.model.Shop.hasMany(app.model.Media, {
  //     foreignKey: 'sid',
  //   })
  // }

  return Shop
}
